package edu.nf.ch05.common;

import edu.nf.ch05.common.resultvo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author gjh
 * @Date 2025/9/28
 * @Description:
 */
@RestControllerAdvice(basePackages = "edu.nf.ch05.web")
@Slf4j
public class GlobalExceptionAdvice {
    @ExceptionHandler(GlobalException.class)
    public ResultVO handleGlobalException(GlobalException e) {
        log.error(e.getMessage(), e);
        return ResultVO.error(e.getErrorCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResultVO handleException(Exception e) {
        log.error(e.getMessage(), e);
        return ResultVO.error(500, "服务器异常，请稍后再试！");
    }
}
